package cn.zaichi.edu.excelcommon.plugs.convertor;

import cn.zaichi.edu.excelcommon.error.ConvertExceptionEnum;
import cn.zaichi.edu.excelcommon.exception.ConvertException;
import cn.zaichi.edu.excelcommon.plugs.ReadConvertor;
import cn.zaichi.edu.excelcommon.plugs.WritConvertor;

/**
 * 是否转换器 1 是，2否
 */
public class YesNoConvertor implements ReadConvertor,WritConvertor {

    private static final int yes=1;
    private static final int no=2;
    @Override
    public Object readerConvert(Object value,String param) {
        if(value==null){
            return null;
        }
        if(value.equals("是")){
            return yes;
        }else if(value.equals("否")){
            return no;
        }else{
            throw new ConvertException(ConvertExceptionEnum.CONVERT_ERROR);
        }
    }

    @Override
    public Object writConvert(Object value,String param) {
        if(value==null){
            return null;
        }
        if(value.equals(yes)){
            return "是";
        }else if(value.equals(no)){
            return "否";
        }else{
            throw new ConvertException(ConvertExceptionEnum.CONVERT_ERROR);
        }
    }
}
